package com.pretty.test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pretty.test.controller.pets.volunteer.dto.VolunteerPageDTO;
import com.pretty.test.controller.pets.volunteer.vo.VolunteerPageVO;
import com.pretty.test.entity.PetsVolunteer;
import com.pretty.test.mapper.PetsVolunteerMapper;
import com.pretty.test.service.IPetsVolunteerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pretty.test.utils.otherutils.Func;
import org.springframework.stereotype.Service;

/**
 * 志愿者服务实现类
 * @author dujianyu
 * @since 2021-04-06
 */
@Service
public class PetsVolunteerServiceImpl extends ServiceImpl<PetsVolunteerMapper, PetsVolunteer> implements IPetsVolunteerService {

    @Override
    public IPage<VolunteerPageVO> selectVolunteerPage(Page<VolunteerPageVO> page, VolunteerPageDTO dto) {
        QueryWrapper queryWrapper  = new QueryWrapper();
        queryWrapper.eq("pv.is_deleted",0);
        queryWrapper.like(!Func.isBlank(dto.getIdNumber()),"id_number",dto.getIdNumber());
        queryWrapper.like(!Func.isBlank(dto.getVolunteerName()),"volunteer_name",dto.getVolunteerName());
        queryWrapper.like(!Func.isBlank(dto.getVolunteerNickname()),"volunteer_nickname",dto.getVolunteerNickname());
        queryWrapper.eq(!Func.isEmpty(dto.getVolunteerStat()),"volunteer_stat",dto.getVolunteerStat());
        queryWrapper.lt(!Func.isEmpty(dto.getCreateTimeEnd()),"pv.create_time",dto.getCreateTimeEnd());
        queryWrapper.gt(!Func.isEmpty(dto.getCreateTimeStart()),"pv.create_time",dto.getCreateTimeStart());
        queryWrapper.orderByDesc("pv.update_time");
        return baseMapper.selectVolunteerPage(page,queryWrapper);
    }
}
